#include <iostream>
#include <map>
#include <vector>
using namespace std;

#include "AVLTree.h"

int main()
{
	// 简单的测试
	/*int a[] = { 4, 3, 6, 1, 3, 5, 15, 7, 16 };
	AVLTree<int, int> tree;
	for (auto e : a)
	{
		tree.Insert(make_pair(e, e));
	}
	tree.Inorder();
	cout << tree.isBalance() << endl;
	return 0;*/
	
	// 进行基准测试
	const int N = 10000000;
	vector<int> v;
	//v.resize(N);

	srand(time(0));

	for (size_t i = 0; i < N; i++)
	{
		v.push_back(rand() + i);
		// cout << v.back() << " ";
	}
	// cout << endl;

	AVLTree<int, int> t;
	int begin1 = clock();
	for (auto e : v)
	{
		t.Insert(make_pair(e, e));
		if (e == 64)
		{
			int x = 0;
		}
		// 调试的时候用的
		// cout << "insert: " << e << " ->" << t.isBalance() << endl;
	}
	// cout << t.isBalance() << endl; // 说明avl树建成了
	int end1 = clock();

	int begin2 = clock();
	for (auto e : v)
	{
		t.Find(e);
	}
	int end2 = clock();
	cout << "节点数：" << t.Size() << endl;
	cout << "高度：" << t.Height() << endl;
	cout << "建树耗时：" << end1 - begin1 << endl;
	cout << "查找耗时：" << end2 - begin2 << endl;
}